package com.xiaofengstu.mcams.web.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaofengstu.mcams.dto.AssetDTO;
import com.xiaofengstu.mcams.web.entity.TAsset;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fengzeng
 * @since 2022-05-07
 */
@Mapper
public interface TAssetMapper extends BaseMapper<TAsset> {

  @Select("select\n" +
      "\t*\n" +
      "from\n" +
      "\t`t_asset` ta\n" +
      "join `t_campus` tc on\n" +
      "\ttc.campus_id = ta.campus_id\n" +
      "join `t_dept` td on\n" +
      "\ttd.dept_id = ta.dept_id\n" +
      "join `t_type` tt on\n" +
      "\ttt.type_id = ta.type_id")
  Page<AssetDTO> getAssetList(Page page);

  @Select("select month (ta.buy_date) as `month` ,count(ta.asset_id) as `count`  from t_asset ta group by Month(ta.buy_date) having `month` is not null ")
  List<Map<String,Integer>> getDates();

  @Select("select\n" +
      "\tmonth (ta.buy_date) as `month` ,\n" +
      "\tsum(ta.value) as `value`\n" +
      "from\n" +
      "\tt_asset ta\n" +
      "group by\n" +
      "\tmonth(ta.buy_date)\n" +
      "having\n" +
      "\t`month` is not null")
  List<Map<String, Integer>> getValues();
}
